# Set the minimum required CMake version
CMAKE_MINIMUM_REQUIRED(VERSION 3.10) # for windows XP compatibility
# Set the project name
PROJECT(mdict-cpp VERSION 1.0.0)

# Suppress developer warnings
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS TRUE)

# Set default build type to Release if not specified
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE "Release")
endif()

# C++ standard
set(CMAKE_CXX_STANDARD 17) # for windows XP compatibility
set(CMAKE_CXX_STANDARD_REQUIRED YES)

# Set build type and compilation flags
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb --std=c++17 ")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall --std=c++17 ")

# Set output directories
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib)
find_package(ZLIB REQUIRED)

# ADD_COMPILE_OPTIONS(-Wno-unused-variable -fpermissive -Wno-sign-compare -Wno-error=sign-compare)

# Add cmake modules path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# INCLUDE(cmake/ProjectMiniz.cmake)
# INCLUDE(cmake/ProjectMinilzo.cmake)
# INCLUDE(cmake/ProjectGTest.cmake)
# INCLUDE(cmake/ProjectTurbobase64.cmake)

add_subdirectory(deps/tbbase64 ${CMAKE_BINARY_DIR}/tbbase64)
add_subdirectory(deps/miniz ${CMAKE_BINARY_DIR}/miniz)

# Add include directories
INCLUDE_DIRECTORIES(
    ${PROJECT_SOURCE_DIR}/src
    ${PROJECT_SOURCE_DIR}/src/include
    ${CMAKE_CURRENT_SOURCE_DIR}/deps/
    ${CMAKE_CURRENT_SOURCE_DIR}/deps/b64/include
    ${ZLIB_INCLUDE_DIR}
)

# Add library search directories
LINK_DIRECTORIES(/usr/local/lib ${CMAKE_CURRENT_BINARY_DIR}/lib)
message(${CMAKE_CURRENT_BINARY_DIR}/lib)

# Add subdirectories
# ADD_SUBDIRECTORY(tests)

# Library target: mdict
ADD_LIBRARY(mdict STATIC src/mdict.cc src/binutils.cc src/ripemd128.c src/adler32.cc src/mdict_extern.cc)
# TARGET_LINK_LIBRARIES(mdict PRIVATE base64 mdictminiz)
TARGET_LINK_LIBRARIES(mdict PRIVATE base64 miniz)
target_include_directories(mdict PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/include)


# Executable target: mydict (for development/testing purposes only)
ADD_EXECUTABLE(mydict src/mydict.cc)
TARGET_LINK_LIBRARIES(mydict PRIVATE mdict)

# 对 Debug 版保留完整符号
target_compile_options(mdict PRIVATE
    $<$<CONFIG:Debug>:-Od -g3 -ggdb>   # GCC/Clang
    $<$<CONFIG:Debug>:/Od /Zi>         # MSVC
)

# MSVC 还需要把符号写进 .pdb
if(MSVC)
    target_compile_options(mdict PRIVATE /Zi)
    target_link_options(mdict PRIVATE /DEBUG)
endif()


